#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
int main()
{
	int m = 0;
	scanf("%d", &m);
	int n = 0;
	for (n = 0; (int)pow(2, n + 1) - 1 < m; n++);
	int tmp = m - (int)pow(2, n - 1) + 1;
	int result = 0;
	if (tmp & 1)
		result = tmp + ((int)pow(2, n - 1) - 1 - tmp) / 2;
	else
		result = tmp + ((int)pow(2, n - 1) - tmp) / 2;
	printf("%d", result);
	return 0;
}